﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace EF.Caching.Impl
{
    public class HttpSessionCache : IPerSessionCache
    {


        public object this[string key]
        {
            get
            {
                var context = HttpContext.Current;
                if (context == null) return null;
                else return context.Session[key];
            }
            set
            {
                var context = HttpContext.Current;
                if (context == null) return;
                context.Session[key] = value;
            }
        }

        public bool Contains(string key)
        {
            var context = HttpContext.Current;
            if (context == null) return false;

            var obj = context.Session[key];
            return obj != null;
        }
    }
}
